#include"qlistwidget_ex.h"
#include<QMouseEvent>
#include<QMimeData>
#include<QDrag>
#include<QApplication>
QListWidget_Ex::QListWidget_Ex(){}
void QListWidget_Ex::mousePressEvent(QMouseEvent *e)
{
    if(e->button()==Qt::LeftButton)
    {
        m_beginPos=e->pos();
    }
    QListWidget::mousePressEvent(e);
}
void QListWidget_Ex::mouseMoveEvent(QMouseEvent *e)
{
    int nDisantce=(e->pos()-m_beginPos).manhattanLength();
    if(nDisantce>=QApplication::startDragDistance())
    {
        QListWidgetItem* curItem=currentItem();
        if(curItem)
        {
            QMimeData* mimeData=new QMimeData;
            mimeData->setText(curItem->text());
            QDrag* drag=new QDrag(this);
            drag->setMimeData(mimeData);
            drag->setPixmap(QPixmap("./image/drag.png"));
            if(Qt::MoveAction==drag->exec(Qt::MoveAction))
            {
                delete curItem;
            }
        }
    }
    QListWidget::mouseMoveEvent(e);
}
